package com.ardo.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.ardo.entity.ResponseResult;
import com.ardo.entity.mall.Banner;
import com.ardo.entity.mall.Category;
import com.ardo.entity.mall.IndexBox;
import com.ardo.entity.mall.Product;
import com.ardo.entity.query.ProductQuery;
import com.ardo.mapper.BaseMapper;
import com.ardo.service.BaseService;
import com.ardo.utils.AppUtils;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@Service
public class BaseServiceImpl implements BaseService {

    @Resource
    private BaseMapper baseMapper;

    @Override
    public String getConf(String keys) {
        String result = "";
        System.out.println("mapper init...");
        ResponseResult res  = new ResponseResult();
        Map<String, Object> map = baseMapper.getUser();
        if(map!=null){
            result = JSONObject.toJSONString(ResponseResult.success(map));

            System.out.println("查询信息：" + result);
        }
        return result;
    }

    @Override
    public String queryParam(String keys) {
        String result = "";
        List<String> attrlist = new ArrayList<String>();
        if(!StringUtils.isEmpty(keys)){
            String attr[] = keys.split(",");
            for (int i = 0; i < attr.length; i++) {
                attrlist.add(attr[i]);
            }
            List<Map<String, Object>> list = baseMapper.queryParam(attrlist);
            if(list != null){
                result = JSONObject.toJSONString(ResponseResult.success(list));
                System.out.println("查询信息：" + result);
            }

        }
        return result;
    }

    public String queryBannerList(){
        String result = "";
        List<Banner> list = baseMapper.queryBannerList();
        if(list!=null){
            result = JSONObject.toJSONString(ResponseResult.success(list));
            System.out.println("查询信息：" + result);
        }
        return result;
    }

    @Override
    public String queryIndexCateBox() {
        String result = "";
        List<IndexBox> list = baseMapper.queryIndexBox();
        if(list!=null){
            result = JSONObject.toJSONString(ResponseResult.success(list));
            System.out.println("查询信息：" + result);
        }
        return result;
    }

    @Override
    public String queryIndexProduct() {
        String result = "";
        return result;
    }

    @Override
    public String queryCategoryList() {
        String result = "";
        List<Category> list = baseMapper.queryCategoryList();
        if(list!=null){
            result = JSONObject.toJSONString(ResponseResult.success(list));
            System.out.println("查询信息：" + result);
        }
        return result;
    }

    @Override
    public String queryProductList(ProductQuery query) {
        String result = "";
        List<Product> list = baseMapper.queryProductList(query);
        if(list!=null){
            result = JSONObject.toJSONString(ResponseResult.success(list));
            System.out.println("查询信息：" + result);
        }
        return result;
    }
}
